//
//  BethelViewController.m
//  MyProject
//
//  Created by yun on 2018/8/9.
//  Copyright © 2018年 yun. All rights reserved.
//

#import "BethelViewController.h"

@interface BethelViewController ()

@property(nonatomic,strong) UIImageView *imgV;


@end

@implementation BethelViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
//    self.imgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bezier.jpg"]];
//    [self.view addSubview:self.imgV];
//    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(self.view);
//        make.width.height.mas_equalTo(150);
//    }];
    [self graphics];
    
}
/**
 * UIGraphicsGetCurrentContext：返回当前图形上下文。默认nil
 UIGraphicsPushContext:使指定的图形上下文成为当前上下文。
 UIGraphicsPopContext:从堆栈顶部删除当前图形上下文，恢复先前的上下文。
 UIRectFillUsingBlendMode:使用指定的混合模式使用当前填充颜色填充矩形。
 此函数在当前图形上下文中绘制矩形。 如果当前图形上下文为nil，则此函数不执行任何操作。
 
 */
- (void)graphics{
    
}

- (void)layerCorner{
    
    CALayer *baseLayer = [CALayer layer];
    baseLayer.position = CGPointMake(100, 150);
    baseLayer.bounds = CGRectMake(0, 0, 140, 140);
    // 阴影是给边框的，所以不设置边框无效
    baseLayer.shadowColor = [UIColor blackColor].CGColor;
    baseLayer.shadowOffset = CGSizeMake(2, 2);
    baseLayer.shadowOpacity = 1;
    baseLayer.cornerRadius = 70;
    baseLayer.borderColor = [UIColor whiteColor].CGColor;
    baseLayer.borderWidth = 2;
    [self.view.layer addSublayer:baseLayer];
    
    CALayer *layer = [CALayer layer];
    layer.position = CGPointMake(100, 150);
    layer.bounds = CGRectMake(0, 0, 140, 140);
    layer.borderColor = [UIColor whiteColor].CGColor;
    layer.borderWidth = 2;
    layer.contents = (__bridge id _Nullable)([UIImage imageNamed:@"bezier.jpg"].CGImage);
    layer.cornerRadius = 70;
    layer.masksToBounds = YES;
    [self.view.layer addSublayer:layer];
    
}


- (void)bezierpath2{
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(50, 500)];
    [path addQuadCurveToPoint:CGPointMake(60, 450) controlPoint:CGPointMake(60, 500)];
    
    // 用CAShapeLayer作为媒介添加到view.layer上显示，否则bezier只能在drawRect里操作。bezier里的一些参数要在CAShapeLayer设置
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = path.CGPath;
    layer.lineJoin = kCALineJoinRound;
    layer.lineCap = kCALineCapRound;
    layer.lineWidth = 5;
    layer.strokeColor = [UIColor greenColor].CGColor;
    layer.fillColor = nil;
    [self.view.layer addSublayer:layer];
    
}

- (void)bezierpath1{
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(5, 5, 140, 140) cornerRadius:100];
    
//    [path addClip];
    // 用CAShapeLayer作为媒介添加到view.layer上显示，否则bezier只能在drawRect里操作。bezier里的一些参数要在CAShapeLayer设置
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.frame = self.imgV.bounds;
    layer.path = path.CGPath;
    layer.lineJoin = kCALineJoinRound;
    layer.lineCap = kCALineCapRound;
//    layer.lineWidth = 2;
    layer.strokeColor = [UIColor greenColor].CGColor;
//    layer.fillColor = [UIColor clearColor].CGColor;
    self.imgV.layer.mask = layer;
}
/**
 *
 + (instancetype)bezierPath;
 // 根据rect创建矩形贝塞尔对象
 + (instancetype)bezierPathWithRect:(CGRect)rect;
 // 根据rect创建椭圆形贝塞尔对象
 + (instancetype)bezierPathWithOvalInRect:(CGRect)rect;
 // 根据rect、cornerRadius创建圆形贝塞尔对象,cornerRadius小于rect半径，则变成圆角；大于则无影响
 + (instancetype)bezierPathWithRoundedRect:(CGRect)rect cornerRadius:(CGFloat)cornerRadius;
 // 指定某个角变成圆角
 + (instancetype)bezierPathWithRoundedRect:(CGRect)rect byRoundingCorners:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii;
 // 画圆弧，clockwise：yes,顺时针；NO，逆时针画相反的圆弧
 + (instancetype)bezierPathWithArcCenter:(CGPoint)center radius:(CGFloat)radius startAngle:(CGFloat)startAngle endAngle:(CGFloat)endAngle clockwise:(BOOL)clockwise;
 
 */

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
